package numberMax

// 一个数字去除n个数求最大值

func NumberMax(array []int, k int) []int {
	if array == nil || len(array) == 0 || k <= 0 {
		return array
	}

	newLength := len(array) - k
	start := 0
	end := 1
	for end < len(array) && k > 0 {
		if start < 0 || array[end] < array[start] {
			array[start+1] = array[end]
			start++
			end++
		} else {
			start--
			k--
		}
	}
	array[start+1] = array[end]
	result := make([]int, newLength)
	for i := 0; i < newLength; i++ {
		result[i] = array[i]
	}
	return result
}
